<html>
<head>
<title>hc_admin_log</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel='stylesheet' type='text/css'
	href='../extjs-4.1.0/resources/css/ext-all.css' />
<script type='text/javascript' src='../extjs-4.1.0/ext-all.js'></script>
<script type="text/javascript" src="../js/head.js"></script>
<!--  <script src="../resources/myproject-lang.js"></script>-->
<!--  <script src="../ext-4.0.7-gpl/ext-all-debug.js"></script>-->
<script type="text/javascript" src="../js/ux/data/PagingMemoryProxy.js"></script>
<script type="text/javascript" src="../js/ux/form/SearchField.js"></script>
<script src="../js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="../js/i18n.js"></script>
<style type="text/css">
/* style rows on mouseover */
.x-grid-row-over .x-grid-cell-inner {
	font-weight: bold;
}
/* shared styles for the ActionColumn icons */
.x-action-col-cell img {
	height: 16px;
	width: 16px;
	cursor: pointer;
}
/* custom icon for the "buy" ActionColumn icon */
.x-action-col-cell img.buy-col {
	background-image: url(../images/accept.png);
}
/* custom icon for the "alert" ActionColumn icon */
.x-action-col-cell img.alert-col {
	background-image: url(../images/image_add.png);
}

.x-ie6 .x-action-col-cell img.buy-col {
	background-image: url(../images/accept.gif);
}

.x-ie6.x-action-col-cell img.alert-col {
	background-image: url(../images/image_add.png);
}

.x-action-col-cell img.refresh {
	background-image: url(../images/refresh.png);
}
/* custom icon for the "alert" ActionColumn icon */
.x-action-col-cell img._cross {
	background-image: url(../images/_cross.png);
}

.x-ie6 .x-action-col-cell img.refresh {
	background-image: url(../images/refresh.gif);
}

.x-ie6.x-action-col-cell img._cross {
	background-image: url(../images/_cross.png);
}

.x-ie6 .x-action-col-cell img {
	position: relative;
	top: -1px;
}
</style>


<script>
function showResult(btn){
    Ext.example.msg('Button Click', 'You clicked the {0} button', btn);
};

function showResultText(bt1, text){
    Ext.example.msg('Button Click', 'You clicked the {0} button and entered the text "{1}".', btn, text);
};

function showResultText(bt1){
    Ext.example.msg('Button Click', 'You clicked the {0} button', btn);
};
Ext.Loader.setConfig({enabled: true});
//Ext.Loader.setPath('Ext.ux', '../ext-4.0.7-gpl/examples/ux');
Ext.require([       
    'Ext.data.*',
	'Ext.form.*',
    'Ext.panel.Panel',
    'Ext.view.View',
    'Ext.layout.container.Fit',
    'Ext.toolbar.Paging',
	'Ext.selection.CheckboxModel',
	'Ext.tip.QuickTipManager',
	'Ext.ux.data.PagingMemoryProxy',
    'Ext.ux.form.SearchField'
]);
Ext.onReady(function() {
	var vmid=0;
    var params;
	Ext.QuickTips.init();
    MultiLang = (function() {
        return {
            init: function() {
                // load ExtJS locale
                params = getCookie("lang");
                i18n.set({
  				  lang: params, 
  				  path: '../resources'
  				});
                if (params) {
                    var url = Ext.util.Format.format('../extjs-4.1.0/locale/ext-lang-{0}.js', params);
                    Ext.Ajax.request({
                        url: url,
                        success: this.onLoadExtLocaleSuccess,
                        failure: this.onLoadExtLocaleFailure,
                        scope: this
                    });
                } else {
                    // no language found, locale of ExtJS will be english as default
                    //this.loadmyprojectLocale();
                	this.setup();
                }
            },
            onLoadExtLocaleSuccess: function(response) {
                try {
                    eval(response.responseText);
                } catch (e) {
                    Ext.Msg.alert('Failure', e.toString());
                }
                //this.loadmyprojectLocale();
                this.setup();
            },
            onLoadExtLocaleFailure: function() {
                Ext.Msg.alert('Failure', 'Failed to load locale file.');
                this.setup();
                //this.loadmyprojectLocale();
            },
            setup: function() {					

					var beginDate=Ext.create('Ext.form.field.Date',{
						//fieldLabel: i18n._('beginDate'),
						fieldLabel:i18n._('beginDate'),
						id:'beginDate',
						labelAlign:'right',
						emptyText:i18n._('PleaseSelect'),
						style:{
							marginTop:'5px'
						},
						format:'Y-m-d H:i:s',
						//width:Ext.getCmp('sort').getWidth(),
						maxValue: new Date()
					});

					var endDate=Ext.create('Ext.form.field.Date',{
						//fieldLabel: i18n._('beginDate'),
						fieldLabel:i18n._('endDate'),
						id:'endDate',
						labelAlign:'right',
						emptyText:i18n._('PleaseSelect'),
						style:{
							marginTop:'5px'
						},
						format:'Y-m-d H:i:s',
						//width:Ext.getCmp('sort').getWidth(),
						maxValue: new Date()
					});

				//define model
				Ext.define('InstanceVO', {
					extend: 'Ext.data.Model',
					fields: [//'DeviceName',
						'id', 'operator', 'actionName','operationResult','parameter','remark',
						{name: 'operationTime', mapping: 'operationTime', type: 'date', dateFormat: 'time'}
					],					
					idProperty: 'id'
				});
				//create the Data Store
				var stGrid2= Ext.create('Ext.data.Store', {
					model: 'InstanceVO',
					remoteSort: true,
					pageSize:15,
					//autoLoad:true,					
					proxy: new Ext.data.proxy.Ajax({
					url: path+'/log4cloud/findAllLog!findAllLog.action',			
					reader: {
				            type: 'json',
				            root: 'resultObject.result',
				            totalProperty: 'resultObject.totalCount'
				        }				        
					}),
					//sortInfo: {field:'id',direction:'DESC'},
					sorters: ["id"]
				});
				var pluginExpanded = true;
				var itemValue='operator';				
				var grid = Ext.create('Ext.grid.Panel', {
				store: stGrid2,
				stateful: true,	
				forceFit: true,
				bbar: Ext.create('Ext.toolbar.Paging', {
					store: stGrid2,					
					displayInfo: true					
				}),
				viewConfig: {
					   stripeRows: true						
				},
				stateId: 'stateGrid',
				dockedItems: [
							 {
								xtype: 'toolbar',
								items: [									
									/*{
										 xtype:'button',
										 text: i18n._('添加'),										 
										 icon: '../images/add.png',
										 handler:function(){												
											//complaintWinForm.show();	
											//formPanel.hidden=false;
										 }
									},*/
									{
										xtype:'tbfill'
									},
									beginDate,
									endDate,
									{
										xtype:'splitbutton',
										text:i18n._('operator'),
										id:'split',
										menu: new Ext.menu.Menu({
											items: [
												{
													text: i18n._('operator'),
													handler: function(){
														Ext.getCmp('split').setText(i18n._('operator'));
														itemValue='operator';
													}
												},
												{
													text: i18n._('actionName'),
													handler: function(){
														Ext.getCmp('split').setText(i18n._('actionName'));
														itemValue='actionName';
													}
												}
											 ]
										})
									},
									{
										labelWidth:50,
										xtype: 'searchfield',
										store: stGrid2,
										id:'orderNoField',
										onTrigger1Click : function(){
											var me = this;
											var	store = me.store;
											var	proxy = store.getProxy();
											var	val;											
											if (me.hasSearch) {
												me.setValue('');
												//alert('**:'+me.paramName);
												//proxy.extraParams[me.paramName] = '';
												proxy.setExtraParam('actionName', null);
												proxy.setExtraParam('operator', null);												
												proxy.extraParams.start = 0;
												//store.load();
												store.loadPage(1,null);
												me.hasSearch = false;
												me.triggerEl.item(0).setDisplayed('none');
												me.doComponentLayout();
											}
										}, 
										onTrigger2Click : function(){//点击查询按钮或回车调用该方法  
											var me = this;																																	
											var store = me.store;											
											var proxy = store.getProxy();											
											store.proxy=proxy;
											var value = me.getValue();											
											if (value.length < 1) {
												me.onTrigger1Click();
												return;
											}
											proxy.setExtraParam('startTime',null) ;
											proxy.setExtraParam('endTime',null);
											if((beginDate.getValue()==null && endDate.getValue()!=null)
													|| (beginDate.getValue()!=null && endDate.getValue()==null))
											{
												Ext.Msg.alert(i18n._('notice'), i18n._('time_cant_null'));
												return;
											}
											if((beginDate.getValue()-endDate.getValue())>0){												
												Ext.Msg.alert(i18n._('notice'), i18n._('time_error'));
												return;
											}
											if(((endDate.getValue()-beginDate.getValue())>0)&& (beginDate.getValue()!=null && endDate.getValue()!=null)){												
												var startdate=Ext.Date.add(beginDate.getValue(),Ext.Date.DAY, 0);
												var enddate=Ext.Date.add(endDate.getValue(),Ext.Date.DAY, 0);
												//proxy.setExtraParam('startTime',startdate) ;
												//proxy.setExtraParam('endTime',enddate);
												proxy.setExtraParam('startTime',Ext.Date.format(startdate, 'Y-m-d H:i:s')) ;
												proxy.setExtraParam('endTime',Ext.Date.format(enddate, 'Y-m-d H:i:s'));
											}
											if(itemValue=='operator'){
												proxy.setExtraParam('actionName', null);
											}else{
												proxy.setExtraParam('operator', null);
											}											
											proxy.setExtraParam(itemValue,value);											
											proxy.extraParams.start = 0;
											//store.load();
											store.loadPage(1,null);
											this.hasSearch = true; 
											//proxy.extraParams[itemValue] = null;
											//proxy.extraParams['startTime']=null;
											//proxy.extraParams['endTime']=null;
											me.triggerEl.item(0).setDisplayed('block');
											me.doComponentLayout();
										}
									}
								]
							  }],
				columnLines:true,
				//bodyBorder:false,
				frame:true,
				border:true,
				columns: [Ext.create('Ext.grid.RowNumberer',{header:i18n._('row_Num'),dataIndex:'item',align:'left'}),
					{
						id: 'id',
						text     : i18n._('日志ID'),
						//flex     : 1,
						sortable : false,
						dataIndex: 'id',
						field:'textfield',
						hidden:true
						
					},
					{						
						text     : i18n._('operator'),
						//flex     : 1,
						sortable : false,
						dataIndex: 'operator',
						field:'textfield'						
					},
					{
						text     : i18n._('actionName'),
						//flex     : 1,
						sortable : false,
						dataIndex: 'actionName',
						field:'textfield'
					},
					{
						text     : i18n._('operationResult'),
						//flex     : 1,
						sortable : false,						
						dataIndex: 'operationResult'
					},
					{
						text     : i18n._('operationTime'),
						//flex     : 1,
						sortable : false,
						dataIndex: 'operationTime',						
						renderer: Ext.util.Format.dateRenderer("Y-m-d H:i:s")
					},
					{
						text     : i18n._('parameter'),
						//flex     : 1,
						sortable : false,
						dataIndex: 'parameter',
						field:'textfield'
						
					},		            
		            {
		                text     : i18n._('other information'),
		                //flex     : 1,
		                sortable : false,		                
		                dataIndex: 'remark',
						field:'textfield'
		            }
				]				
				});//����grid
				stGrid2.load();
				//stGrid2.load(params:{{startTime:beginDate.getValue(),endTime:endDate.getValue()}});
				grid.store.sort([{ property: "id", direction: "DESC" }]);
				Ext.create('Ext.Viewport',{
					layout:'fit',
					width:'100%',
					items:[{
					xtype:'panel',
					id:'panel_one',
					title:i18n._('UAAS')+'&nbsp;&nbsp;>>&nbsp;&nbsp;'+i18n._('Log')+i18n._('search'),
					width:'100%',
					layout:'fit',
					tools:[{
					type:'pin',
					handler:function(){
					  window.parent.document.getElementsByTagName('iframe')[0].src='hc_admin_log.html';
					}
					},{
					type:'refresh',
					handler:function(){
					  window.parent.document.getElementsByTagName('iframe')[0].src='hc_admin_log.html';
					}	
					},{
					type:'left',
					handler:function(){
					  history.go(-1);
					}
					}],
					items:[
					{
						 xtype:'panel',
						 layout:'fit',
						 border:false,
						 items:grid
					  }
					]
					}]//panel
					});			
				
            }
        };
    })();

    MultiLang.init();
});

 function getCookie(name){
         var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
         if(arr != null) return unescape(arr[2]);
		 return null;
 }
</script>
</head>
<body>
</body>
</html>